package com.xky.example_student.utils;

import io.jsonwebtoken.*;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.context.annotation.Configuration;

/**
 * @author .29.
 * @create 2024-03-16 0:29
 * @description 生成JwtToken， 获取JwtToken中加密的信息， 判断JwtToken是否合法
 *
 */
@Configuration
public class JwtUtil {
    //创建默认的密钥与加密算法，提供给空参构造器调用
    private static final String defaultBase64EncodingSecretKey = "eb^29*be";
    private static final SignatureAlgorithm defaultSignatureAlgorithm = SignatureAlgorithm.HS256;

    //空参构造器，内部调用有参构造器传入默认的密钥、加密算法
    public JwtUtil(){
        this(defaultBase64EncodingSecretKey, defaultSignatureAlgorithm);
    }

    private static String base64EncodingSecretKey = "";//密钥
    private static SignatureAlgorithm signatureAlgorithm = null;//加密算法

    //有参构造器，创建对象并传入参数为成员变量base64EncodingSecretKey与signatureAlgorithm赋值
    public JwtUtil(String base64EncodingSecretKey, SignatureAlgorithm signatureAlgorithm){
        this.base64EncodingSecretKey = Base64.encodeBase64String(base64EncodingSecretKey.getBytes());;
        this.signatureAlgorithm = signatureAlgorithm;
    }

}



